package com.yanyeori.rest.controller;

import com.yanyeori.framework.core.context.TraceContext;
import com.yanyeori.framework.core.model.WebResponse;
import com.yanyeori.service.file.api.client.LocalFileClient;
import com.yanyeori.service.file.api.client.OssFileClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author chenkuan
 * @since 2022/10/6 17:23
 */
@RestController
@RequestMapping("/testController")
public class TestController {
    private final Logger log = LoggerFactory.getLogger(getClass());

    @Autowired
    private LocalFileClient localFileClient;
    @Autowired
    private OssFileClient ossFileClient;

    @PostMapping("/uploadLocalFile")
    public WebResponse uploadLocalFile(@RequestPart MultipartFile file) {
        return localFileClient.upload(file);
    }

    @PostMapping("/uploadOssFile")
    public WebResponse uploadOssFile(@RequestPart MultipartFile file) {
        return ossFileClient.upload(file);
    }

    @GetMapping("/getOssDownloadUrl")
    public WebResponse getOssDownloadUrl(@RequestParam String filePath) {
        return ossFileClient.getDownloadUrl(filePath);
    }

    @GetMapping("/test")
    public WebResponse test(@RequestParam String param, @RequestBody TraceContext traceContext) {
        log.info("get param: {}, traceContext: {}", param, traceContext);
        return WebResponse.ok();
    }
}
